– Selva V Pasupathy, HSBC Global Resourcing, Hyderabad
Normally when a userform is initiated you would see it with a blue title bar by default everytime. But if you want to use the userform as a title form, then one would be interested in removing the titlebar. One more userful Tip I came across at Colo’s Excel Junk Room – Masaru Kaji. The following code shows userform with no titlebar and closes after few seconds.
|
HOW SHOULD I USE THE FOLLOWING CODE
Copy the following code in standard code module.
'///place these procedures on a standard module
Option Explicit
Public Const GWL_STYLE = -16
Public Const WS_CAPTION = &HC00000
Public Declare Function GetWindowLong _
Lib "user32" Alias "GetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong _
Lib "user32" Alias "SetWindowLongA" ( _
ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Declare Function DrawMenuBar _
Lib "user32" ( _
ByVal hWnd As Long) As Long
Public Declare Function FindWindowA _
Lib "user32" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
'____________________________________________________________
Sub Form_Show()
'Hide Excel
Application.Visible = False
'To close a form automatically
Application.OnTime Now, "Form_Close"
UserForm1.Show
End Sub
'____________________________________________________________
Sub Form_Close()
'To close a form automatically
Dim datWaitTime As Date
datWaitTime = TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 3)
Application.Wait datWaitTime
Unload UserForm1
Application.Visible = True
End Sub
'____________________________________________________________
Sub HideTitleBar(frm As Object)
Dim lngWindow As Long
Dim lFrmHdl As Long
lFrmHdl = FindWindowA(vbNullString, frm.Caption)
lngWindow = GetWindowLong(lFrmHdl, GWL_STYLE)
lngWindow = lngWindow And (Not WS_CAPTION)
Call SetWindowLong(lFrmHdl, GWL_STYLE, lngWindow)
Call DrawMenuBar(lFrmHdl)
End Sub
'____________________________________________________________
|
Copy following code into the userform code.
'//Place these procedures on the UserForm1 module
Option Explicit
Private Sub UserForm_Initialize()
HideTitleBar Me
End Sub
'____________________________________________________________
Private Sub UserForm_Click()
'Close this userform
Unload Me
End Sub
'____________________________________________________________
|
To download Example file CLICK HERE
Leave a comment